package com.msb.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.annotation.Annotation;
import java.util.Map;

/**
 * @author sunpeng
 * @Date 2021-06-07 16:32
 */
@Configuration
public class GlobalException3 implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView mv = new ModelAndView();
        if(e instanceof NullPointerException){
            mv.setViewName("/error2.jsp");
        }else if(e instanceof ArithmeticException){
            mv.setViewName("/error1.jsp");
        }
        /*Map<String, Object> model = mv.getModel();
        model.put("error", e);*/
        mv.addObject("error",e);
        return mv;
    }
}
